package Lee_code;

public class Lee_1221 {
    public int balancedStringSplit(String s) {
        int len = s.length();
        int start  =0;
        int res = 0;
        for(int i=0; i<len; i=i+2){
            if (judge(start, i, s)){
                start=i;
                res++;
            }
        }
        return res;
    }

    private boolean judge(int start, int end, String s) {
        int r_num = 0, l_num=0;
        for (int i=0; i<2; i++){
            if(s.charAt(i)=='R'){
                r_num++;
            }
            else
                l_num++;
        }
        return r_num==l_num;
    }
}
